package com.zijie.shoprbacapi.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zijie.rbac.model.Perm;
import com.zijie.rbac.model.Resource;
import com.zijie.rbac.service.PermService;
import com.zijie.shoprbacapi.mapper.PermMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class PermServiceImpl implements PermService {
    private PermMapper PermMapper;

@Autowired
    public void setPermMapper(PermMapper permMapper) {
        PermMapper = permMapper;
    }

    @Override
    public Page<Perm> findAll(Page<Perm> page, Perm perm) {
        return PermMapper.findAll(page,perm);
    }

    @Override
    public boolean add(Perm perm) {
        return PermMapper.insert(perm)==1;
    }

    @Override
    public boolean update(Perm perm) {
        return PermMapper.updateById(perm)==1;
    }

    @Override
    public int deleteById(Integer id) {
        return PermMapper.deleteById(id);
    }

    @Override
    public int deleteByIds(List<Integer> ids) {
        return PermMapper.deleteByIds(ids);
    }

    @Override
    public int assignResources(Integer permId, Integer[] resourceIds) {
        return PermMapper.assignResources(permId,resourceIds);
    }

    @Override
    public List<Resource> resources(Integer permId) {
    return PermMapper.resources(permId);
    }

    @Override
    public int deleteResources(Integer permId, Integer resourceId) {
    return PermMapper.deleteResources(permId,resourceId);
    }



    @Override
    public Perm findById(Integer permId) {
        return PermMapper.selectById(permId);
    }
}
